<?php
require_once "../Common/values.php";
	
# define ou to search
    

$ad = ldap_connect($ldapaddress)
          or die("Couldn't connect to AD!");
    $attributes = array("givenname", "sn", "title", "pager", "mail" ,"telephonenumber", "department", "physicaldeliveryofficename");
	# define filter
    #$filter = "(&(department=*)!(sn=parts))";

    $filter = '(sn=*'.$_POST[lastname].'*)';
#echo $filter;
   $bd = ldap_bind($ad,$ldapuser,$ldappwd)
          or die("Couldn't connect to AD!");
  
    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);

    
    
 #run this string on evey search
    $result = ldap_search($ad, $dn, $filter, $attributes);
    $entries = ldap_get_entries($ad, $result);

#table with results
echo '<h2>Results</h2>';
echo '<table border=1 width=75%><tr bgcolor=#1DBAEF><td>Tel EXT:</td><td>Firstname</td><td>Lastname</td><td>Office</td><td>Department</td><td>Job Title</td><td>TEL. NUMBER
</td><td>Email</td></tr>';
    for ($i=0; $i<$entries["count"]; $i++)
    {
        echo '<form action="publicnew.php" method="POST"><tr><td><input type=Hidden name="phone" value="'.$entries[$i]["telephonenumber"][0].'">'.$entries[$i]["telephonenumber"][0].'</td><td><input type=hidden name=\"1name\" value="'.$entries[$i]["givenname"][0].'">'.$entries[$i]["givenname"][0].'</td><td>'.$entries[$i]["sn"][0].'</td><td><input type=hidden name="branch" value="'.$entries[$i]["physicaldeliveryofficename"][0].'">'.$entries[$i]["physicaldeliveryofficename"][0].'</td><td><input type=hidden name="department" value="'.$entries[$i]["department"][0].'">'.$entries[$i]["department"][0].'</td><td>'.$entries[$i]["title"][0].'</td><td>'.$entries[$i]["pager"][0].'</td><td>'.$entries[$i]["mail"][0].'</td><td><input type=submit value=Select></td><td><input type=hidden name="requestor" value="'.$entries[$i]["givenname"][0].' ',$entries[$i]["sn"][0].'"><input type=hidden name="mail" value="'.$entries[$i]["mail"][0].'"></TD></tr></form>';
    }



echo '</table>';

ldap_unbind($ad);

?>

